
var vm = new Vue({
    el: '#app',
    data: {
        user: {},
        menuList: {},
        password: '',
        newPassword: '',
        navTitle: "欢迎页",
        baseInfo: {},
        ifUser:false
    },

    methods: {
        getPermissionsList: function () {
            $.getJSON(baseURL + "sys/user/getPermissionsList", function (r) {
                window.permissions = r.permissions;
                console.info(r.permissions);
            })
        },
        getUser: function () {
            $.getJSON(baseURL + "sys/user/info", function (r) {
                vm.user = r.user;
                window.user = r.user;
                console.info(r.user);
            }).then(function () {
                vm.ifUser=true
            });
        },
        updatePassword: function () {
            layer.open({
                type: 1,
                skin: 'layui-layer-molv',
                title: "修改密码",
                area: ['550px', '270px'],
                shadeClose: false,
                content: jQuery("#passwordLayer"),
                btn: ['修改', '取消'],
                btn1: function (index) {
                    if (vm.password!=vm.newPassword) {
                        $('#error').show();
                        return;
                    }
                    var data = "password=" + vm.password + "&newPassword=" + vm.newPassword;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "sys/user/password",
                        data: data,
                        dataType: "json",
                        success: function (r) {
                            if (r.code == 0) {
                                layer.close(index);
                                layer.alert('修改成功', function () {
                                    location.reload();
                                });
                            } else {
                                layer.alert(r.msg);
                            }
                        }
                    });
                },
                btn2:function (index) {
                    vm.password = '';
                    vm.newPassword = '';
                    $('#error').hide();
                }
            });
        },
        logout: function () {
            showWarningMsg('确定要退出系统吗',function () {
                $.getJSON(baseURL + "sys/logout", function (r) {
                });
                //删除本地token
                localStorage.removeItem("token");
                //跳转到登录页面
                location.href = baseURL + 'login.html';
            },null);
        },
        cancellation:function () {
            showWarningMsg('确定要注销账户吗！注销后所有登记了的无人机将被注销，是否需要继续？',function () {
                ajaxSubmit("/member/cancellation",null,function (r) {
                    if (r.code == 0) {
                        showSuccessMsg("操作成功！",function () {
                            reloadPage();
                        });
                    }
                })
            },null);
        }
    },
    created: function () {
        this.getPermissionsList();
        this.getUser();
    }
});

